$TITLE ('INSERT TASK IN READY LIST')
$SYMBOLS
$NOXREF
$NOCOND
$NOMOD51
$NORB
$PAGELENGTH(80) PAGEWIDTH(110)
;************************************************************************
;*									*
;*    R T X - 5 1  :  INSERT TASK IN READY LIST                         *
;*							     		*
;*----------------------------------------------------------------------*
;*                                                                      *
;*    Filename     :   RTXINS.A51                                       *
;*    Language     :   Keil A-51                                        *
;*    Dev. system  :   Keil uVision2                                    *
;*    Targetsystem :   Any system based upon 8051 up                    *
;*                                                                      *
;*    Purpose      :   Insert specified task id at the end of the       *
;*                     ready list.                                      *
;*								     	*
;*----------------------------------------------------------------------*
;* Rev. |  Released   | Programmer    | Comments                        *
;*----------------------------------------------------------------------*
;* 0.1  |  4.1.1990   | E. Glatz      | For V3.18                       *
;* 0.2  | 10.4.1991   | Th. Fischler  | Adapted to Keil A-51,           *
;*      |             |               | Macro INSERT_RDY_PRIO splitted  *
;*      |             |               | to INSERT_RDY_PRIO and          *
;*      |             |               | INSERT_RDY_PRIO_W_A (Akku holds *
;*      |             |               | the Task-ID)                    *
;*      |  7.5.1991   |               | P2-Addressing eliminated        *
;*      |  4.6.1992   | Th. Fischler  | Derived from RTXINS.INC         *
;* 5.00 | 20.10.1994  | E. Glatz      | Release 5.00                    *
;* 7.00 | 13.11.2001  | T. Mueller    | Release 7.00                    *
;************************************************************************
;*    Copyright 1991 .. 2001 METTLER  &  FUCHS  AG,  CH-8953 Dietikon   *
;************************************************************************


;*----------------------------------------------------------------------*
;*	I M P O R T S
;*----------------------------------------------------------------------*

$INCLUDE (RTXCONST.INC)
$INCLUDE (RTXEXTRN.INC)


;*----------------------------------------------------------------------*
;*	E X P O R T S
;*----------------------------------------------------------------------*

PUBLIC   ?RTX_INSERT_RDY_PRIO


;*----------------------------------------------------------------------*
;*	P R O C E D U R E S
;*----------------------------------------------------------------------*

;*----------------------------------------------------------------------*
;*      I N S E R T _ R D Y _ P R I O
;*----------------------------------------------------------------------*
;*      Inserts the task, the task_id of it is contained in an
;*      int. RAM variable (ACC not possible), at the correct position
;*      depending on its priority in the ready-list.
;*      Supported are 4 different task priorities and max.
;*      16 active tasks.
;*----------------------------------------------------------------------*
;*      Input:   - ACC holds the Task-Id of the task to be inserted
;*
;*      Output:  - Changes DPTR and  ACC
;*
;*      Task-Interrupts must be disabled on entry of this function !!
;*----------------------------------------------------------------------*

?RTX?INSERT_RDY_PRIO?RTXIHAND   SEGMENT CODE
                                RSEG    ?RTX?INSERT_RDY_PRIO?RTXIHAND

?RTX_INSERT_RDY_PRIO:
               MOV   DPH,#HIGH(?RTX_SYS_PAGE)      ; Select RAM page 0
               JB    ACC.7, PRIO23                 ; Insert task_id in
               JB    ACC.6, PRIO1                  ; correct prio. FIFO

PRIO0:         INC   ?RTX_RDY_COUNT0               ; Insert task_id in
               MOV   DPL, ?RTX_RDY_LAST0           ; FIFO 0
               MOVX  @DPTR, A
               ; increment pointer and test for overflow
               INC   ?RTX_RDY_LAST0
               MOV   A, ?RTX_RDY_LAST0
               CJNE  A, #LOW(?RTX_RDY_PRIO0_END), ENDL
               MOV   ?RTX_RDY_LAST0, #LOW(?RTX_RDY_PRIO0)
               RET

PRIO1:         INC   ?RTX_RDY_COUNT1               ; Insert task_id in
               MOV   DPL, ?RTX_RDY_LAST1           ; FIFO 1
               MOVX  @DPTR, A
               ; increment pointer and test for overflow
               INC   ?RTX_RDY_LAST1
               MOV   A, ?RTX_RDY_LAST1
               CJNE  A, #LOW(?RTX_RDY_PRIO1_END), ENDL
               MOV   ?RTX_RDY_LAST1, #LOW(?RTX_RDY_PRIO1)
               RET

PRIO23:        JB    ACC.6, PRIO3

PRIO2:         INC   ?RTX_RDY_COUNT2               ; Insert task_id in
               MOV   DPL, ?RTX_RDY_LAST2           ; FIFO 2
               MOVX  @DPTR, A
               ; increment pointer and test for overflow
               INC   ?RTX_RDY_LAST2
               MOV   A, ?RTX_RDY_LAST2
               CJNE  A, #LOW(?RTX_RDY_PRIO2_END), ENDL
               MOV   ?RTX_RDY_LAST2, #LOW(?RTX_RDY_PRIO2)
               RET

PRIO3:         INC   ?RTX_RDY_COUNT3               ; Insert task_id in
               MOV   DPL, ?RTX_RDY_LAST3           ; FIFO 3
               MOVX  @DPTR, A
               ; increment pointer and test for overflow
               INC   ?RTX_RDY_LAST3
               MOV   A, ?RTX_RDY_LAST3
               CJNE  A, #LOW(?RTX_RDY_PRIO3_END), ENDL
               MOV   ?RTX_RDY_LAST3, #LOW(?RTX_RDY_PRIO3)

ENDL:          RET

;
;   END OF MODULE
;
	END
